package com.entity;

import java.io.Serializable;
import javax.persistence.*;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.springframework.format.annotation.DateTimeFormat;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the CUSTOMER database table.
 * 
 */
@Entity
@Table(name="CUSTOMER")
@NamedQuery(name="Customer.findAll", query="SELECT c FROM Customer c")
public class Customer implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name="CUSTOMER_CUSNO_GENERATOR", sequenceName="CUSSEQ",initialValue=1,allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CUSTOMER_CUSNO_GENERATOR")
	private Long cusno;
	
	private String cname;//姓名
	
	private String compname;//公司名称
	
	@Temporal(TemporalType.DATE)
	@JSONField(format="yyyy-MM-dd")
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date createdate;//创建日期
	
	private String csex;//性别
	
	private String ctel;//电话
	
	private String debt;//负债情况
	
	private Integer isgh;//是否属于公海
	
	private Boolean isDelete;
	
	

	public Boolean getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(Boolean isDelete) {
		this.isDelete = isDelete;
	}

	@Temporal(TemporalType.DATE)
	@JSONField(format="yyyy-MM-dd")
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date firstsigndate;//首次签约时间

	@ManyToOne
	@JoinColumn(name="SCUSNO")
	private Customer scus;//上级客户
	
	@OneToMany(mappedBy="scus")//下级客户
	@JSONField(serialize=false)
	private List<Customer> dcus;

	//bi-directional many-to-one association to Chanceinfo
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Chanceinfo> chanceinfos;
	
	//bi-directional many-to-one association to Detailedrequirement
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Detailedrequirement> detailedrequirements;
		
	//bi-directional many-to-one association to Solution
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Solution> solutions;

	//bi-directional many-to-one association to Rivalfirm
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Rivalfirm> rivalfirms;
	
	//bi-directional many-to-one association to Offerinfo
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Offerinfo> offerinfos;
	
	//bi-directional many-to-one association to Complain
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Complain> complains;

	//bi-directional many-to-one association to Cusdraw
	@OneToMany(mappedBy = "customer"/* ,fetch=FetchType.EAGER */)
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.DELETE})
	private List<Cusword> cuswords;//客户扩展字段


	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="USER_ID")
	private User user;//负责员工

	//bi-directional many-to-many association to Linkman
	@ManyToMany(mappedBy = "customers"/* ,fetch=FetchType.EAGER */)
	@Cascade({CascadeType.SAVE_UPDATE})
	private List<Linkman> linkmans;//联系人

	//bi-directional many-to-one association to Notelist
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Notelist> notelists;

	//bi-directional many-to-one association to Outstock
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Outstock> outstocks;

	//bi-directional many-to-one association to Repairorder
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Repairorder> repairorders;

	//bi-directional many-to-one association to Serve
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Serve> serves;

	//bi-directional many-to-one association to Solicitude
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Solicitude> solicitudes;

	//bi-directional many-to-one association to Order
	@OneToMany(mappedBy="customer")
	@JSONField(serialize=false)
	private List<Order> orders;
	{
		cuswords = new ArrayList<Cusword>();
	}
	public Customer() {
	}

	public Long getCusno() {
		return this.cusno;
	}

	public void setCusno(Long cusno) {
		this.cusno = cusno;
	}

	public String getCname() {
		return this.cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

	public String getCompname() {
		return this.compname;
	}

	public void setCompname(String compname) {
		this.compname = compname;
	}

	public Date getCreatedate() {
		return this.createdate;
	}

	public void setCreatedate(Date createdate) {
		this.createdate = createdate;
	}

	public String getCsex() {
		return this.csex;
	}

	public void setCsex(String csex) {
		this.csex = csex;
	}

	public String getCtel() {
		return this.ctel;
	}

	public void setCtel(String ctel) {
		this.ctel = ctel;
	}

	public String getDebt() {
		return this.debt;
	}

	public void setDebt(String debt) {
		this.debt = debt;
	}

	public Date getFirstsigndate() {
		return this.firstsigndate;
	}

	public void setFirstsigndate(Date firstsigndate) {
		this.firstsigndate = firstsigndate;
	}
	
	public Integer getIsgh() {
		return isgh;
	}

	public void setIsgh(Integer isgh) {
		this.isgh = isgh;
	}

	public Customer getScus() {
		return scus;
	}

	public void setScus(Customer scus) {
		this.scus = scus;
	}

	public List<Customer> getDcus() {
		return dcus;
	}

	public void setDcus(List<Customer> dcus) {
		this.dcus = dcus;
	}
	
	public Customer addDcus(Customer dcus) {
		getDcus().add(dcus);
		dcus.setScus(this);
		
		return dcus;
	}
	
	public Customer removeDcus(Customer dcus) {
		getDcus().remove(dcus);
		dcus.setScus(null);
		
		return dcus;
	}

	public List<Chanceinfo> getChanceinfos() {
		return this.chanceinfos;
	}

	public void setChanceinfos(List<Chanceinfo> chanceinfos) {
		this.chanceinfos = chanceinfos;
	}

	public Chanceinfo addChanceinfo(Chanceinfo chanceinfo) {
		getChanceinfos().add(chanceinfo);
		chanceinfo.setCustomer(this);

		return chanceinfo;
	}

	public Chanceinfo removeChanceinfo(Chanceinfo chanceinfo) {
		getChanceinfos().remove(chanceinfo);
		chanceinfo.setCustomer(null);

		return chanceinfo;
	}
	
	

	public List<Detailedrequirement> getDetailedrequirements() {
		return this.detailedrequirements;
	}

	public void setDetailedrequirements(List<Detailedrequirement> detailedrequirements) {
		this.detailedrequirements = detailedrequirements;
	}
	
	public Detailedrequirement addDetailedrequirement(Detailedrequirement detailedrequirement){
		getDetailedrequirements().add(detailedrequirement);
		detailedrequirement.setCustomer(this);
		
		return detailedrequirement;
	}
	
	public Detailedrequirement removeDetailedrequirement(Detailedrequirement detailedrequirement){
		getDetailedrequirements().remove(detailedrequirement);
		detailedrequirement.setCustomer(null);
		
		return detailedrequirement;
	}
	
	public List<Solution> getSolutions() {
		return solutions;
	}

	public void setSolutions(List<Solution> solutions) {
		this.solutions = solutions;
	}

	public Solution addSolution(Solution solution){
		getSolutions().add(solution);
		solution.setCustomer(this);
		
		return solution;
	}
	
	public Solution removeSolution(Solution solution){
		getSolutions().remove(solution);
		solution.setCustomer(null);
		
		return solution;
	}

	public List<Rivalfirm> getRivalfirms() {
		return rivalfirms;
	}

	public void setRivalfirms(List<Rivalfirm> rivalfirms) {
		this.rivalfirms = rivalfirms;
	}
	
	public Rivalfirm addRivalfirm(Rivalfirm rivalfirm){
		getRivalfirms().add(rivalfirm);
		rivalfirm.setCustomer(this);
		
		return rivalfirm;
	}
	
	public Rivalfirm removeRivalfirm(Rivalfirm rivalfirm){
		getRivalfirms().remove(rivalfirm);
		rivalfirm.setCustomer(null);
		
		return rivalfirm;
	}

	public List<Offerinfo> getOfferinfos() {
		return offerinfos;
	}

	public void setOfferinfos(List<Offerinfo> offerinfos) {
		this.offerinfos = offerinfos;
	}
	
	public Offerinfo addOfferinfo(Offerinfo offerinfo){
		getOfferinfos().add(offerinfo);
		offerinfo.setCustomer(this);
		
		return offerinfo;
	}
	
	public Offerinfo removeOfferinfo(Offerinfo offerinfo){
		getOfferinfos().remove(offerinfo);
		offerinfo.setCustomer(null);
		
		return offerinfo;
	}

	public List<Complain> getComplains() {
		return this.complains;
	}

	public void setComplains(List<Complain> complains) {
		this.complains = complains;
	}

	public Complain addComplain(Complain complain) {
		getComplains().add(complain);
		complain.setCustomer(this);

		return complain;
	}

	public Complain removeComplain(Complain complain) {
		getComplains().remove(complain);
		complain.setCustomer(null);

		return complain;
	}

	public List<Cusword> getCuswords() {
		return this.cuswords;
	}

	public void setCuswords(List<Cusword> cuswords) {
		this.cuswords = cuswords;
	}
	
	public Cusword addCusword(Cusword cusword) {
		getCuswords().add(cusword);
		cusword.setCustomer(this);
		
		return cusword;
	}
	
	public Cusword removeCusword(Cusword cusword) {
		getCuswords().remove(cusword);
		cusword.setCustomer(null);
		
		return cusword;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Linkman> getLinkmans() {
		return this.linkmans;
	}

	public void setLinkmans(List<Linkman> linkmans) {
		this.linkmans = linkmans;
	}

	public List<Notelist> getNotelists() {
		return this.notelists;
	}

	public void setNotelists(List<Notelist> notelists) {
		this.notelists = notelists;
	}

	public Notelist addNotelist(Notelist notelist) {
		getNotelists().add(notelist);
		notelist.setCustomer(this);

		return notelist;
	}

	public Notelist removeNotelist(Notelist notelist) {
		getNotelists().remove(notelist);
		notelist.setCustomer(null);

		return notelist;
	}

	public List<Outstock> getOutstocks() {
		return this.outstocks;
	}

	public void setOutstocks(List<Outstock> outstocks) {
		this.outstocks = outstocks;
	}

	public Outstock addOutstock(Outstock outstock) {
		getOutstocks().add(outstock);
		outstock.setCustomer(this);

		return outstock;
	}

	public Outstock removeOutstock(Outstock outstock) {
		getOutstocks().remove(outstock);
		outstock.setCustomer(null);

		return outstock;
	}

	public List<Repairorder> getRepairorders() {
		return this.repairorders;
	}

	public void setRepairorders(List<Repairorder> repairorders) {
		this.repairorders = repairorders;
	}

	public Repairorder addRepairorder(Repairorder repairorder) {
		getRepairorders().add(repairorder);
		repairorder.setCustomer(this);

		return repairorder;
	}

	public Repairorder removeRepairorder(Repairorder repairorder) {
		getRepairorders().remove(repairorder);
		repairorder.setCustomer(null);

		return repairorder;
	}

	public List<Serve> getServes() {
		return this.serves;
	}

	public void setServes(List<Serve> serves) {
		this.serves = serves;
	}

	public Serve addServe(Serve serve) {
		getServes().add(serve);
		serve.setCustomer(this);

		return serve;
	}

	public Serve removeServe(Serve serve) {
		getServes().remove(serve);
		serve.setCustomer(null);

		return serve;
	}

	public List<Solicitude> getSolicitudes() {
		return this.solicitudes;
	}

	public void setSolicitudes(List<Solicitude> solicitudes) {
		this.solicitudes = solicitudes;
	}

	public Solicitude addSolicitude(Solicitude solicitude) {
		getSolicitudes().add(solicitude);
		solicitude.setCustomer(this);

		return solicitude;
	}

	public Solicitude removeSolicitude(Solicitude solicitude) {
		getSolicitudes().remove(solicitude);
		solicitude.setCustomer(null);

		return solicitude;
	}

	public List<Order> getOrders() {
		return this.orders;
	}

	public void setOrders(List<Order> orders) {
		this.orders = orders;
	}

	public Order addOrder(Order order) {
		getOrders().add(order);
		order.setCustomer(this);

		return order;
	}

	public Order removeOrder(Order order) {
		getOrders().remove(order);
		order.setCustomer(null);

		return order;
	}

	@Override
	public String toString() {
		return "Customer [cusno=" + cusno + ", cname=" + cname + ", compname=" + compname + ", cuswords=" + cuswords
				+ ", linkmans=" + linkmans + "]";
	}

	
}